package com.yuluke.ylsaudiorecorder.record;

public class StateInstance {

    public static final int STATE_IDLE = 1;
    public static final int STATE_RECORD_STARTED = 2;
    public static final int STATE_RECORD_STOPED = 3;
    public static final int STATE_RECORD_ERR = 4;

    private int mState;
    private volatile static StateInstance mInstance;

    private StateInstance() {
        mState = STATE_IDLE;
    }

    public static StateInstance getInstance() {
        if (mInstance == null) {
            synchronized (StateInstance.class) {
                if (mInstance == null) mInstance = new StateInstance();
            }
        }
        return mInstance;
    }

    public int getState() {
        return mState;
    }

    public boolean isStarted() {
        return mState == STATE_RECORD_STARTED;
    }

    public boolean isError() {
        return mState == STATE_RECORD_ERR;
    }

    public void change(int state) {
        if (mState != state) mState = state;
    }
}
